package com.bnzj.cloud.business.core.persistence.entity;

import com.bnzj.core.persistence.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonBackReference;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;

@Getter
@Setter
@ToString(exclude = {"role", "user"}, callSuper = true)
@Entity
@Table(name = "bnz_sys_role_user")
@Schema(description = "角色与用户的关系")
public class SysRoleUser extends BaseEntity {
    private static final long serialVersionUID = -3957960150961625908L;
    private Long roleId;
    private Long userId;

    @JoinColumn(name = "roleId", insertable = false, updatable = false)
    @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
    @JsonBackReference(value = "relation-role-user")
    private SysRole role;

    @JoinColumn(name = "userId", insertable = false, updatable = false)
    @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
    @JsonBackReference(value = "relation-user-role")
    private SysUser user;
}
